Parse urls from text file
A text link extractor can be useful if you're doing cross-browser testing. For example, if you're writing tests for moderating comments or forum posts, then a common action that you need to do is find all links in the comments and posts and check if they are allowed. With this program, you can prepare such test cases.
You can feed this program several different text fragments or multi-line strings and the program will return all links in them. You can then use the extracted links as the expected output results for the tests. Looking for more web developer tools? Try these! Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Learn more. Ask Question. Asked 7 years, 10 months ago. Active 4 years, 10 months ago. Viewed 30k times. Improve this question. Mike B Mike B 8, 23 23 gold badges 63 63 silver badges 92 92 bronze badges. Sounds scary, depending on what you want to do with the extracted URL Add a comment. Active Oldest Votes. Did you try: egrep -o 'https? Improve this answer. StephaneChazelas You're right. However, I assumed that the URL is preceded and followed by a space unless at the beginning or the end of line.
As currently posted, the one-line version is as follows:? CodeGnome CodeGnome 7, 1 1 gold badge 16 16 silver badges 25 25 bronze badges. Please include the regex in your answer instead of linking to it. Instead, I had to do the following Python 3 :. I do think requests is the best option. Also note the possibility of setting encoding manually. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Given a URL to a text file, what is the simplest way to read the contents of the text file? Ask Question. Asked 12 years, 4 months ago. Active 10 months ago. Viewed k times. Improve this question. Chris Chris 3, 6 6 gold badges 28 28 silver badges 40 40 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Simon Streicher 2, 1 1 gold badge 21 21 silver badges 26 26 bronze badges.
For posterity, the code to do this in Python 3 is import urllib. Andrew Mao Andrew Mao There's really no need to read line-by-line.
0コメント